<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>全部笔记 - NoteX</title>
    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <style>
        body {
            font-family: 'Microsoft YaHei', sans-serif;
            background: #f8fafc;
        }

        .note-item {
            border: 1px solid #e5e7eb;
            border-radius: 8px;
            padding: 15px;
            margin-bottom: 15px;
            background: #ffffff;
            transition: all 0.2s ease;
        }

        /* 为不同标签设置不同的背景色 */
        .note-item.tag-blue { background-color: rgba(59, 130, 246, 0.05); border-left: 4px solid rgb(59, 130, 246); }
        .note-item.tag-green { background-color: rgba(16, 185, 129, 0.05); border-left: 4px solid rgb(16, 185, 129); }
        .note-item.tag-yellow { background-color: rgba(245, 158, 11, 0.05); border-left: 4px solid rgb(245, 158, 11); }
        .note-item.tag-red { background-color: rgba(239, 68, 68, 0.05); border-left: 4px solid rgb(239, 68, 68); }
        .note-item.tag-indigo { background-color: rgba(99, 102, 241, 0.05); border-left: 4px solid rgb(99, 102, 241); }
        .note-item.tag-purple { background-color: rgba(139, 92, 246, 0.05); border-left: 4px solid rgb(139, 92, 246); }
        .note-item.tag-pink { background-color: rgba(236, 72, 153, 0.05); border-left: 4px solid rgb(236, 72, 153); }
        .note-item.tag-orange { background-color: rgba(249, 115, 22, 0.05); border-left: 4px solid rgb(249, 115, 22); }

        .note-item:hover {
            box-shadow: 0 2px 8px rgba(0,0,0,0.05);
            transform: translateY(-1px);
        }

        .tag {
            display: inline-block;
            padding: 2px 8px;
            border-radius: 12px;
            font-size: 12px;
            margin-right: 5px;
            transition: all 0.2s ease;
        }

        .note-actions {
            opacity: 0;
            transition: opacity 0.2s;
        }

        .note-item:hover .note-actions {
            opacity: 1;
        }
    </style>
</head>
<body class="min-h-screen">
    <div class="container mx-auto px-4 py-8">
        <div class="flex justify-between items-center mb-6">
            <h1 class="text-2xl font-bold">全部笔记</h1>
            <a href="/" class="text-blue-500 hover:text-blue-600">
                <i class="fas fa-arrow-left mr-2"></i>返回首页
            </a>
        </div>

        <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
            {% for note in notes %}
            <div class="note-item tag-{{ tag_colors[note.tags[0]] if note.tags else 'blue' }}" data-note-id="{{ note.id }}">
                <div class="flex justify-between items-start">
                    <div>
                        <h3 class="font-medium">{{ note.title }}</h3>
                        <p class="text-sm text-gray-500 mt-1">{{ note.content }}</p>
                        <div class="mt-2">
                            {% for tag in note.tags %}
                            <span class="tag bg-{{ tag_colors[tag] }}-100 text-{{ tag_colors[tag] }}-800">{{ tag }}</span>
                            {% endfor %}
                        </div>
                    </div>
                    <div class="flex flex-col items-end">
                        <div class="text-sm text-gray-500">{{ note.created_at }}</div>
                        <div class="note-actions flex space-x-2 mt-2">
                            <button onclick="editNote({{ note.id }})" class="text-blue-500 hover:text-blue-600">
                                <i class="fas fa-edit"></i>
                            </button>
                            <button onclick="deleteNote({{ note.id }})" class="text-red-500 hover:text-red-600">
                                <i class="fas fa-trash"></i>
                            </button>
                        </div>
                    </div>
                </div>
            </div>
            {% endfor %}
        </div>
    </div>

    <script>
        function editNote(noteId) {
            window.location.href = `/notes/${noteId}/edit`;
        }

        async function deleteNote(noteId) {
            if (!confirm('确定要删除这条笔记吗？')) return;

            try {
                const response = await fetch(`/notes/${noteId}/delete`, {
                    method: 'DELETE'
                });
                const data = await response.json();
                
                if (data.success) {
                    const noteElement = document.querySelector(`[data-note-id="${noteId}"]`);
                    noteElement.style.animation = 'fadeOut 0.3s ease-out forwards';
                    noteElement.addEventListener('animationend', () => {
                        noteElement.remove();
                    });
                } else {
                    alert('删除失败，请重试');
                }
            } catch (error) {
                console.error('Error:', error);
                alert('删除失败，请重试');
            }
        }
    </script>
</body>
</html> 